package com.promise.jokerdream.database.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.promise.jokerdream.database.entity.CurrentAccountEntity
import kotlinx.coroutines.flow.Flow

/**
 * 当前账户数据访问对象
 */
@Dao
interface CurrentAccountDao {
    
    /**
     * 插入或更新当前账户ID
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertOrUpdate(currentAccount: CurrentAccountEntity)
    
    /**
     * 更新当前账户ID
     */
    @Update
    suspend fun update(currentAccount: CurrentAccountEntity)
    
    /**
     * 获取当前账户ID
     */
    @Query("SELECT * FROM current_account WHERE id = 1 LIMIT 1")
    suspend fun getCurrentAccount(): CurrentAccountEntity?
    
    /**
     * 获取当前账户ID (Flow)
     */
    @Query("SELECT * FROM current_account WHERE id = 1 LIMIT 1")
    fun getCurrentAccountFlow(): Flow<CurrentAccountEntity?>
    
    /**
     * 清除当前账户ID
     */
    @Query("UPDATE current_account SET currentUserId = NULL WHERE id = 1")
    suspend fun clear()
}

